@extends('admin/index')
@section('name')
    <h1><span class="label label-default"> 后台用户管理  </span></h1>
    <hr>

    <table class="table table-bordered  table-hover" id="tent">
        <tr>
            <th>ID</th>
            <th>名字</th>
            <th>邮箱</th>
            <th>类型</th>
            <th>注册时间</th>
            <th>最后登录时间</th>
            <th>操作</th>
        </tr>
        @foreach($result as $v)
        <tr>
            <td>{{$v->id}}</td>
            <td>{{$v->a_name}}</td>
            <td>{{$v->a_email}}</td>
            <td>
                @if("$v->a_type" == 0)
                    普通管理员
                @else
                    超级管理员
                @endif
            </td>
            <td>{{$v->a_tragtime}}</td>
            <td>{{$v->a_lasttime}}</td>
            <td>
                <a href="/admin/upd/{{$v->id}}" class="btn btn-info">修改</a>
                <button class="btn btn-danger" id="but1" onclick="del({{$v->id}})">删除</button>
            </td>
        </tr>
        @endforeach
    </table>

    <script>
        function del($id) {
            var id = $id;

            $.ajax({
                type: 'get',
                url: "{{url('/admin/del')}}/" + id,
                data: id, //发送请求数据
                success: function (data) {
                    console.log(data);
                    if (data == 1) {
                        $("table#tent tr").click(function () {
                            $(this).remove();
                        });
                        window.location.href='{{url('/admin/user')}}';
                    } else {
                        alert('删除失败');
                    }
                },
                error:function () {
                    alert('ajax请求失败');
                }
            });
        }
    </script>

    @if(!empty(session('error')))
        <script>
            alert('{{session('error')}}')
        </script>
    @endif


@endsection
